// 组织管理，筛选组件基础类
import {Component, Watch, Prop, Vue} from 'vue-property-decorator'

@Component({})
export default class selectItem extends Vue{
    name:string = 'select-item'

    @Prop()
    data
   
    @Prop({
        default: ''
    })
    initFilterKey
    
    filterKey:string = this.initFilterKey

    @Prop()
    random

    @Watch('random')
    onRandomChange(){
        this.filterKey = this.initFilterKey;
    }

    get tableData():any[]{

        let cache = [... this.data];

       cache = cache.filter(item =>{
            return item.name.match(this.filterKey)
        })

        return cache
    }

    maxH:number = 300
    
    // 控制表格最大高度
    get tableH (){
        let h = 42;

        let mathH = this.data.length ?  this.data.length * h : h
        return  mathH> this.maxH ? this.maxH : mathH;  
    }

    

     // 判断是否点击同一项
    isSameRow:number = 1
    
    select(row, index){
        let tableEle:any = this.$refs['table'];
        
        // 清除重复选项
        if(!this.isSameRow){
            row = {}
            tableEle.clearCurrentRow()
        }
        
        this.isSameRow = 0;
        this.$emit('select', row);   
    }

    setFilterKey (key:string = ''){
        this.filterKey = key;
    }

    currentRowChange(){
        this.isSameRow++
    }

    
}
